import Request from '../util/Request';
import md5 from 'js-md5';
import AccountConfig from '../config/AccountConfig';
import App from '../config/App';

const create = (param, callback) => {
    let url = App.HOST + '/user/createUser.json';
    param = {
        ...param,
        sign: md5(AccountConfig.COMPOSE + param.account + param.passWord),
        apply: AccountConfig.APPLY_NAME
    };

    let req = Request.getRequest(param, url);
    Request.post(req, callback);
};

const login = (param, callback, fail) => {
    let url = App.HOST + '/user/login.json';

    let md5PassWord = md5(param.passWord);
    param = {
        ...param,
        passWord: md5PassWord,
        sign: md5(AccountConfig.COMPOSE + param.account + md5PassWord),
        apply: AccountConfig.APPLY_NAME
    };

    let req = Request.getRequest(param, url);
    Request.post(req, callback, fail);
};

export default {
    create: create,
    login: login
}
